package com.github.cloud.service;

import com.github.cloud.feign.UserService;
import com.github.cloud.model.vo.UserVo;
import com.github.cloud.util.UserDetailsImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * Created by guxiaowei on 2018/3/7.
 * 重写oauth2 UserDetailService覆盖默认方法
 */
@Service("userDetailService")
public class UserDetailServiceImpl implements UserDetailsService,Serializable {

    @Autowired
    private UserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserVo userVo = userService.findUserByUsername(username);
        return new UserDetailsImpl(userVo);
    }
}
